unit PacocInput;

interface
uses
  Windows, Controls, SysUtils;

procedure GetMousePos(var x, y: Integer);
procedure ActivateClient;
function  GetClientWindowHandle: Integer;
procedure SetClientWindowHandle(H: Integer);
procedure SetDesktopAsClient;
procedure SetTargetDC(DC: Integer);
procedure GetClientDimensions(var Width, Height: Integer);
function  GetKeyCode(Key: Char): Byte;

implementation

uses
  ClickIt;

procedure GetMousePos(var x, y: Integer);
begin
  x:= Mouse.CursorPos.X - ClickIt.ClientBox.Left;
  y:= Mouse.CursorPos.Y - ClickIt.ClientBox.Top;
end;

procedure ActivateClient;
begin
  SetForegroundWindow(ClickIt.Client);
end;

function GetClientWindowHandle: Integer;
begin
  Result:= ClickIt.Client;
end;

procedure SetClientWindowHandle(H: Integer);
begin
  ReleaseDC(ClickIt.Client, ClickIt.ClientDC);
  ClickIt.Client:= H;
  ClickIt.ClientDC:= GetDC(ClickIt.Client);
  GetWindowRect(ClickIt.Client, ClickIt.ClientBox);
end;

procedure SetDesktopAsClient;
begin
  ReleaseDC(ClickIt.Client, ClickIt.ClientDC);
  ClickIt.Client:= 0;
  ClickIt.ClientDC:= GetDC(0);
  GetWindowRect(0, ClickIt.ClientBox);
end;

procedure SetTargetDC(DC: Integer);
begin
  ReleaseDC(ClickIt.Client, ClickIt.ClientDC);
  ClickIt.ClientDC:= DC;
  ClickIt.Client:= WindowFromDC(DC);
  GetWindowRect(0, ClickIt.ClientBox);
end;

procedure GetClientDimensions(var Width, Height: Integer);
begin
  Width:= ClickIt.ClientBox.Right - ClickIt.ClientBox.Left + 1;
  Height:= ClickIt.ClientBox.Bottom - ClickIt.ClientBox.Top + 1;
end;

function GetKeyCode(Key: Char): Byte;
begin
  Result:= ord(Key);
end;

end.
